{	Problem: http://codeforces.ru/problemset/problem/69/B
 	Verdict: Accepted
}
var n,m,i,j,res,cur:longint; l,r,t,c:array[0..110] of longint;
begin
read(n,m);
for i:=1 to m do read(l[i],r[i],t[i],c[i]);
t[0]:=maxlongint;
res:=0;
for i:=1 to n do begin
  cur:=0;
  for j:=1 to m do
    if (l[j]<=i) and (r[j]>=i) and (t[j]<t[cur]) then cur:=j;
  if cur<>0 then inc(res,c[cur]);
end;
write(res);
end.